package com.flowerplus.store.common.data.utils.ui;

import android.content.Context;
import android.telephony.TelephonyManager;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

/**
 * Created by ems on 2017/2/28.
 */

public class UIUtil {

    Context mContext;


    public UIUtil(Context context) {
        mContext = context;
    }



    /**
     * 显示软键盘
     *
     * @param view
     */
    public void showInput(View view) {
        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
    }

    /**
     * 隐藏软键盘
     *
     * @param view
     */
    public void hideInput(View view) {
        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0); //强制隐藏键
    }

    /**
     * 如果输入法在窗口上已经显示，则隐藏，反之则显示
     */
    public void toggleInput() {
        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }

    /**
     * 获取当前手机系统版本号
     *
     * @return 系统版本号
     */
    public String getSystemVersion() {
        return android.os.Build.VERSION.RELEASE;
    }

    /**
     * 获取手机国际识别码IMEI
     * */
    public  String getSystemIMEI(){
        TelephonyManager systemService = (TelephonyManager)mContext
                .getSystemService(Context.TELEPHONY_SERVICE);
        return  systemService.getImei();
    }


    /**
     * 获取手机型号
     *
     * @return 手机型号
     */
    public String getSystemModel() {
        return android.os.Build.MODEL;
    }

    /**
     * 获取手机号
     * @return
     */
    public String getPhoneNumber() {
        TelephonyManager systemService = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
        return systemService.getLine1Number();
    }
}
